<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : discuz.api.php   FILE_PATH : D:\webroot\mulitishop\plug\discuz.api.php
 * ....DISCUZ和X-SPACE的接口文件
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Sat Nov 03 15:46:58 CST 2007
 */
require ("../global.inc.php");

class DiscuzApi extends CommonFrameWork{
	function main(){
		switch($this->_input['action']){
			case "login":
				$this->_login();
				break;
		}
		//$_SESSION['s'] = 'ddd';
		print_r($_SESSION);
	}

	/**
	 * 登录接口
	 *
	 */
	function _login(){
		/**
		 * 创建会员对象
		 */
		require_once ("member.class.php");
		$objmember = new Member();

		/**
		* 插件接口类
		*/
		require_once("api.class.php");
		$id = base64_decode($this->_input['id']);
		$password = base64_decode($this->_input['password']);
		
		if ($this->_input['auth'] == md5($id.$password)){
			$member_array = $objmember->getMemberInfo($id,"1");
			$this->_input['txtloginname'] = $member_array['login_name'];
			$this->_input['txtPassword'] = $password;
			$objmember->loginMember($this->_input);
			//登录成功
			if (is_array($member_array)){
				/**
		    	 * 创建商铺对象
		     	 */
				if (!is_object($obj_shop)){
					require_once("shop.class.php");
					$obj_shop = new ShopClass();
				}
				$shop_id = $obj_shop->getShopID($member_array['login_name'],"login_name","1");  //得到商城ID
				if ($shop_id > 0){
					$_SESSION["s_shop"]['id'] = $shop_id;
					$this->shopid = $_SESSION["s_shop"]['id'];
				}
				$_SESSION["s_login"]['login'] = 1;
				$_SESSION["s_login"]['id'] = $member_array['member_id'];            //会员ID
				$_SESSION["s_login"]['name'] = $member_array['login_name'];    //登陆名称
				$_SESSION["s_login"]['type'] = $member_array['member_type'];  //会员类型

				setcookie("c_login_name",$member_array['login_name'],time()+60*24*365);
				//并把会员信息存放到COOKIE中,DISCUZ,X-SPACE接口
				$cookievalue = Api::authcode("" . $member_array['password'] . "\t$secques\t" . $member_array['member_id'] . "", 'ENCODE',$this->_configinfo['discuz']['authkey']);
				//echo $this->_configinfo['discuz']['authkey'];exit;
				$this->setCookies("auth",$cookievalue);
				print_r($_SESSION);
			}


		}
	}
}
$discuz_api = new DiscuzApi();
$discuz_api->main();
unset($discuz_api);
?>